<?php

class Application_Model_Contactos extends Sgit_Model
{  
    protected $_name = 'contactos';
    protected $_primary = 'id';


    public function getContacto($id)
    {
        return $this->getContactos(array(), $id);
    }


    public function getContactos($values = array(), $id = null)
    {

        $select = $this->getAdapter()->select();
        $select->from(array($this->_name))
            ->joinLeft('zonas', 'zonas.id = contactos.id_zona', array('zona'=>'nombre'));
       
        if (!is_null($id))
        {
            $select->where("id= ?", $id);

        } else
        {
            if (is_numeric($values['id_zona']))
                $select->where('lineas.id_zona= ?', $values['id_zona'],INTEGER);
            if (is_numeric($values['id_proyecto']))
                $select->where('lineas.id_proyecto= ?', $values['id_proyecto'],INTEGER);
            if (is_numeric($values['id_sala']))
                $select->where('lineas.id_sala= ?', $values['id_sala'],INTEGER);
            if ($values['numero'])
                $select->where('lineas.numero= ?', $values['numero']);
            if ($values['administrativo'])
                $select->where('lineas.administrativo= ?', $values['administrativo']);
            if (is_numeric($values['grupo']))
                $select->where('lineas.grupo= ?', $values['grupo'],INTEGER);
           if (is_numeric($values['par']))
                $select->where('lineas.par= ?', $values['par'],INTEGER);

        }


        $rows = $this->getAdapter()->fetchAll($select);

        if (is_null($id))
            return $rows;
        else
            return $rows[0];


    }
    
    
    
} 




